﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Text;
using SCSService;

namespace SCS.Core.Models.ModelsFontend
{
    public class LanguageModel
    {
        #region "Language"
        public static List<System_Language> GetListLanguageBySiteGuid(int siteGuid)
        {
            SCSService.LanguageService langSvc = new LanguageService();
            return langSvc.GetListLanguageBySiteGuid(siteGuid);
        }

        public static HtmlTextWriter GetListLanguageBuilder(int id, string uri,string host,int typeBox)
        {
            HtmlTextWriter sb = new HtmlTextWriter(new System.IO.StringWriter());
            return ListLanguageBuilder(ref sb, id, uri,host,typeBox);
        }

        public static HtmlTextWriter ListLanguageBuilder(ref HtmlTextWriter sb, int id, string uri,string host,int typeBox)
        {

            List<SCSService.System_Language> listLanguage = Models.ModelsFontend.LanguageModel.GetListLanguageBySiteGuid(id);
            
            sb.WriteBeginTag("ul");
            sb.WriteAttribute("class", "lbox");
            sb.Write(">");
            
            sb.Write("\n");
            foreach (var item in listLanguage)
            {

                sb.WriteBeginTag("li");
                sb.Write(">");

                if (typeBox == 1)
                { 
                    //Link Name
                    sb.WriteBeginTag("a");
                    if (host == "localhost")
                    {
                        sb.WriteAttribute("href", "/" + id + "/" + item.countryCode + uri);
                    }
                    else
                    {
                        sb.WriteAttribute("href", "/" + item.countryCode + uri);
                    }
                    sb.WriteAttribute("name", "LanguageCode");
                    sb.WriteAttribute("id", item.LanguagesID.ToString());
                    //sb.WriteAttribute("onclick", "changeLanguage('" + item.LanguagesID.ToString() + "')");
                    sb.Write(">");
                    sb.Write(item.countryName);
                    sb.WriteEndTag("a");
                }
                else if (typeBox == 2)
                {
                    //Link Flag
                    sb.WriteBeginTag("a");
                    if (host == "localhost")
                    {
                        sb.WriteAttribute("href", "/" + id + "/" + item.countryCode + uri);
                    }
                    else
                    {
                        sb.WriteAttribute("href", "/" + item.countryCode + uri);
                    }
                    sb.WriteAttribute("name", "LanguageCode");
                    sb.WriteAttribute("id", item.LanguagesID.ToString());
                    //sb.WriteAttribute("onclick", "changeLanguage('" + item.LanguagesID.ToString() + "')");
                    sb.Write(">");
                    sb.WriteBeginTag("img");
                    sb.WriteAttribute("src","http://"+host+ item.countryImg);
                    sb.WriteAttribute("name", "LanguageCode");
                    sb.WriteAttribute("id", item.LanguagesID.ToString());
                    sb.WriteAttribute("alt", item.countryName);
                    sb.WriteAttribute("height", "24px");
                    sb.WriteAttribute("width", "24px");
                    sb.Write("/>");
                    sb.WriteEndTag("a");
                }
                
               
                sb.WriteEndTag("li");
                sb.Write("\n");
            }
            sb.WriteEndTag("ul");

            return sb;
        }

        public static List<System_Language> GetListLanguage()
        {
            SCSService.LanguageService langSvc = new LanguageService();
            return langSvc.GetListLanguage();
        }

        public static System_Language GetLanguageByID(int id)
        {
            SCSService.LanguageService langSvc = new LanguageService();
            return langSvc.GetLanguageByID(id);
        }

        public static int GetLanguageIDByCountryCode(string code)
        {
            SCSService.LanguageService langSvc = new LanguageService();
            return langSvc.GetLanguageIDByCountryCode(code);
        }

        public static System_Language_Tag GetTagBySiteGuidAndLanguageIDandTagName(int languageID, int siteguid, string TagName)
        {
            SCSService.LanguageService langSvc = new LanguageService();
            return langSvc.GetTagBySiteGuidAndLanguageIDandTagName(languageID,siteguid,TagName);
        }
        #endregion
    }
}